package com.hkts.naturalgas.utils;

import io.github.bucket4j.Bandwidth;
import io.github.bucket4j.Bucket4j;
import io.github.bucket4j.local.LocalBucket;
import org.springframework.data.redis.core.convert.Bucket;

import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.util.stream.IntStream;

/**
 * @ClassNamePucketUtils
 * @Description
 * @Author yck
 * @Date2020-11-09 10:35
 * @Version V1.0
 **/
public class PucketUtils {
    public static void main(String[] args) throws InterruptedException{
        Bandwidth limit = Bandwidth.simple(20, Duration.ofSeconds(1));
        LocalBucket bucket = Bucket4j.builder().addLimit(limit).build();
        while(true){
            bucket.asScheduler().consume(1);
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date()));
        }
    }


}
